<?php

namespace support;

use app\component\User;

class XunshanContainer extends Container
{
    /**
     * @param mixed ...$arguments
     * @return Response
     */
    public static function response(...$arguments)
    {
        /** @var Response $response */
        $response = static::make(Response::class, []);
        if (empty($arguments)) {
            return $response;
        } else {
            $response->withStatus($arguments[0]);
            if (isset($arguments[1]) && is_array($arguments[1]) && !empty($arguments[1])) {
                $response->withHeaders($arguments[1]);
            }
            if (isset($arguments[2]) && strlen($arguments[2]) > 0 && $arguments[2] !== null) {
                $response->withBody($arguments[2]);
            }
            return $response;
        }
    }

    /**
     * @return User
     */
    public static function user()
    {
        if (session('__user') !== null) {
            return session('__user');
        }
        $user = static::make(User::class, []);
        session(['__user' => $user]);
        return $user;
    }
}